package org.xq.softcup.mq.util;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BasicJson {
    private static final BasicJsonReader basicJsonReader = new BasicJsonReader();
    private static final BasicJsonwriter basicJsonwriter = new BasicJsonwriter();

    public static String toJson(Object object)
    {
        return basicJsonwriter.toJson(object);
    }

    public static Map<String, Object> parseMap(String json)
    {
        return basicJsonReader.parseMap(json);
    }

    public static List<Object> parseList(String json)
    {
        return basicJsonReader.parseList(json);
    }

    public static void main(String[] args)
    {
        Map<String, Object> result = new HashMap();
        result.put("code", Integer.valueOf(200));
        result.put("msg", "success");
        result.put("arr", Arrays.asList(new String[] { "111", "222" }));
        result.put("float", Float.valueOf(1.11F));
        result.put("temp", null);

        String json = toJson(result);
        System.out.println(json);

        Map<String, Object> mapObj = parseMap(json);
        System.out.println(mapObj);

        List<Object> listInt = parseList("[111,222,33]");
        System.out.println(listInt);
    }
}
